package com.example.adapter;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.olddoctor.R;
import com.example.tools.adbanner.entity.AdInfo;
import com.example.tools.adbanner.view.AdBannerView;
import com.xdandroid.simplerecyclerview.Adapter;

import java.util.ArrayList;
import java.util.List;

import static com.example.administrator.olddoctor.R.id.view;

/**
 * Created by Administrator on 2016/10/18.
 */

public class HotItemAdapter extends Adapter{

    //Banner类型
    public static final int TYPE_BANNER = 100;
    //文本类型
    public static final int TYPE_TEXT = 200;

    private String mResultValueBanner;
    private List<String> list;
    private final static int AD_ONCLICK = 0X44;
    private Context mContext;
    private String firstmonth;
    private ArrayList<AdInfo> mAdInfoList = new ArrayList<AdInfo>();

    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case AD_ONCLICK:

                    if (Integer.parseInt(msg.obj.toString()) == 0) {

                    } else if (Integer.parseInt(msg.obj.toString()) == 1) {

                    } else if (Integer.parseInt(msg.obj.toString()) == 2) {
                    }
                    break;
                default:
                    break;
            }
        }
    };

    public void setBannerList(String resultValueBanner) {
        mResultValueBanner = resultValueBanner;
//        notifyDataSetChanged();
    }

    public void setInfoList(List<String> resultValueInfo) {
        list = resultValueInfo;
        notifyDataSetChanged();
    }

    public HotItemAdapter(Context context) {
        mResultValueBanner = "";
        list = new ArrayList<String>();
        mContext = context;
    }

    @Override
    protected void onLoadMore(Void please_make_your_adapter_class_as_abstract_class) {

    }

    @Override
    protected boolean hasMoreElements(Void let_activity_or_fragment_implement_these_methods) {
        return false;
    }

    @Override
    protected RecyclerView.ViewHolder onViewHolderCreate(ViewGroup parent, int viewType) {
        if (viewType == TYPE_BANNER) {
            return new BannerVH(LayoutInflater.from(parent.getContext()).inflate(R.layout.header_adbanner, parent, false));
        } else {
            return new TextVH(LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_hotitem, parent, false));
        }
    }

    @Override
    protected void onViewHolderBind(RecyclerView.ViewHolder holder, int position, int viewType) {
        if (viewType == TYPE_BANNER) {
            BannerVH bannerVH = (BannerVH) holder;

            mAdInfoList.clear();
//        for (int i = 0; i < 3; i++) {
//            AdInfo mAdInfo = new AdInfo();
//            mAdInfo.setAdvImg("http://123.56.93.196//resource/img/20160829/14724530431336.jpg");
//            mAdInfo.setAdvDesc("");
//            mAdInfoList.add(mAdInfo);
//        }
            AdInfo mAdInfo = new AdInfo();
            mAdInfo.setAdvImg("http://img3.redocn.com/20100412/20100405_9319ee379dbef301ebd0ZdhVXIlC5YAc.jpg");
            mAdInfo.setAdvDesc("");
            mAdInfoList.add(mAdInfo);

            AdInfo mAdInfo1 = new AdInfo();
            mAdInfo1.setAdvImg("http://pic.35pic.com/normal/07/79/32/3360417_130529212152_2.jpg");
            mAdInfo1.setAdvDesc("");
            mAdInfoList.add(mAdInfo1);

            AdInfo mAdInfo2 = new AdInfo();
            mAdInfo2.setAdvImg("http://pic26.nipic.com/20130117/11734311_093848282000_2.jpg");
            mAdInfo2.setAdvDesc("");
            mAdInfoList.add(mAdInfo2);

            bannerVH.mAdBannerView.setClickFlag(AD_ONCLICK);
            bannerVH.mAdBannerView.init(mHandler, mAdInfoList);
            bannerVH.mAdBannerView.startPlay();
//        mAdBannerView.stopPlay();
        } else {
            final TextVH textVH = (TextVH) holder;

        }
    }

    @Override
    protected int getViewType(int position) {
        if (position == 0) {
            return TYPE_BANNER;
        } else {
            return TYPE_TEXT;
        }
    }

    @Override
    protected int getCount() {
        return list.size();
    }

    @Override
    protected int getItemSpanSizeForGrid(int position, int viewType, int spanCount) {
        return 1;
    }


    static final class TextVH extends RecyclerView.ViewHolder {
        TextVH(View v) {
            super(v);
//            image = (ImageView) itemView.findViewById(R.id.club_imageView);
//            name = (TextView) itemView.findViewById(R.id.club_name);
//            con = (TextView) itemView.findViewById(R.id.club_con);
//            address = (TextView) itemView
//                    .findViewById(R.id.club_address);
        }

        public ImageView image;
        public TextView name, address, con;
    }
    static final class BannerVH extends RecyclerView.ViewHolder {
        BannerVH(View v) {
            super(v);
//            address = (TextView) itemView.findViewById(R.id.address);
//            right = (LinearLayout) itemView.findViewById(R.id.right);
              mAdBannerView = (AdBannerView) itemView.findViewById(R.id.home_adbanner);
        }

        public AdBannerView mAdBannerView;
        public TextView address;
        public LinearLayout right;
    }
}
